home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Online / SpeakFreely / src / adpcm / sgicaudio.c < prev    next >
C/C++ Source or Header  |  2000-05-18  |  2KB  |  75 lines

  1. /*
  2. ** sgicaudio - Simple AIFF file compressor.
  3. **
  4. ** Needs libaf, which is in the Digital Media developers option.
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <audio.h>
  9. #include <audiofile.h>
  10. #include "adpcm.h"
  11.  
  12. #define NFRAMES 8000
  13.  
  14. struct adpcm_state astate;
  15. short ibuf[NFRAMES];
  16. char obuf[NFRAMES/2];
  17.  
  18. main(argc, argv)
  19.     int argc;
  20.     char **argv;
  21. {
  22.     AFfilehandle af;
  23.     FILE *of;
  24.     long fmt, width;
  25.     long count;
  26.     
  27.     if ( argc < 2 || argc > 3 ) {
  28.     fprintf(stderr, "Usage: %s aifffile [adpcmfile]\n", argv[0]);
  29.     exit(1);
  30.     }
  31.     /*
  32.     ** Open input file and check format
  33.     */
  34.     if ( (af = AFopenfile(argv[1], "r", NULL)) == 0 ) {
  35.     perror(argv[1]);
  36.     exit(1);
  37.     }
  38.     AFgetsampfmt(af, AF_DEFAULT_TRACK, &fmt, &width);
  39.     if ( AFgetchannels(af, AF_DEFAULT_TRACK) != 1 || fmt != AF_SAMPFMT_TWOSCOMP
  40.     || width != 16 ) {
  41.     fprintf(stderr, "%s: %s: only 16bit mono integer files supported\n",
  42.         argv[0], argv[1]);
  43.     exit(1);
  44.     }
  45.     if ( AFgetrate(af, AF_DEFAULT_TRACK) != 8000.0 )
  46.       fprintf(stderr, "%s: %s: WARNING: not 8Khz\n", argv[0], argv[1]);
  47.     /*
  48.     ** Open output file
  49.     */
  50.     if ( argc == 3 ) {
  51.     if ( (of=fopen(argv[2], "w")) == 0 ) {
  52.         perror(argv[2]);
  53.         exit(1);
  54.     }
  55.     } else {
  56.     of = stdout;
  57.     }
  58.     /*
  59.     ** Copy loop
  60.     */
  61.     while (1) {
  62.     count = AFreadframes(af, AF_DEFAULT_TRACK, ibuf, NFRAMES);
  63.     if ( count <= 0 ) break;
  64.     if ( count & 1 ) {
  65.         ibuf[count] = ibuf[count-1];
  66.         count++;
  67.     }
  68.     adpcm_coder(ibuf, obuf, count, &astate);
  69.     fwrite(obuf, 1, (count+1)/2, of);
  70.     }
  71.     fclose(of);
  72.     AFclosefile(af);
  73.     exit(0);
  74. }
  75.